package com.xiaomi.back.service.commoditys.impl;

import com.xiaomi.back.dao.commoditys.CommodityDao;
import com.xiaomi.back.service.commoditys.CommoditysService;
import com.xiaomi.pojo.Commoditys;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CommoditysServiceImpl implements CommoditysService {
    @Autowired
    private CommodityDao commodityDao;


    @Override
    public List<Commoditys> getCommodityslist() {
        return commodityDao.getCommodityslist();
    }

    @Override
    public List<Commoditys> getCommoditysByName(String uname, int cid) {
        return commodityDao.getCommoditysByName(uname,cid);
    }

    @Override
    public boolean CommoditysAdd(Commoditys commoditys) {
        boolean result = false;
        int num = commodityDao.CommoditysAdd(commoditys);
        if (num == 1) {
            result = true;
        }
        return result;
    }

    @Override
    public int CommoditysUpadte(int state, int cid) {
        return commodityDao.CommoditysUpdate(state,cid);
    }

    @Override
    public Commoditys CommoditysById(int id) {
        return commodityDao.CommoditysById(id);
    }

    //根据id  修改商品描述
    @Override
    public int UpDesc(String state, int cid) {
        return commodityDao.UpDesc(state,cid);
    }

    @Override
    public int UpRecommend(int recommend, int cid) {
        return commodityDao.UpRecommend(recommend,cid);
    }

    @Override
    @Transactional
    public Boolean addCommInfo(int pbid, String comname, String miaoshu, Double depraice, String config, int count, String picture) {
        Boolean result=false;

        //添加商品表
        int getcomm=commodityDao.GteCommodity(pbid,comname,miaoshu);
        if(getcomm==1){
            //获取 cid
            Commoditys commoditys=commodityDao.getCId(pbid,comname,miaoshu);
            int cid=commoditys.getCid();
            //存商品详情表
            int addComminfo=commodityDao.addComminfo(depraice,config,cid,count,picture);
            if(addComminfo==1){
                result=true;
            }else{
                result=false;
            }
        }
        return result;
    }


}
